package com.abigdreamer.im.server.cmd.resouse;

import java.util.ArrayList;
import java.util.List;

import com.abigdreamer.im.server.cmd.command.Command;

public class CMDConfig {

	private List<Mapping> mapping=new ArrayList<Mapping>();
	private List<CommandBean> commandBeans=new ArrayList<CommandBean>();
	private String cmdInfo;
	
	public List<Mapping> getMapping() {
		return mapping;
	}
	public void setMapping(List<Mapping> mapping) {
		this.mapping = mapping;
	}
	public List<CommandBean> getCommandBeans() {
		return commandBeans;
	}
	public void setCommandBeans(List<CommandBean> commandBeans) {
		this.commandBeans = commandBeans;
	}
	public Mapping getMappByID(String commandID){
		Mapping map=null;
		for(Mapping ma:mapping){
			if(ma.getId().equals(commandID)){
				map=ma;
				break;
			}
		}
		return map;
	}
	public CommandBean getCommandBeanByID(String commandName) {
		CommandBean bean=null;
		String beanname="";
		for(Mapping map:mapping){
			if(map.getId().equals(commandName)){
				beanname=map.getBeanName();
				 break;
			}
		}
		for(CommandBean cbean:commandBeans){
			if(cbean.getName().equals(beanname)){
				 bean=cbean;
				 break;
			}
		}
		return bean;
	}

	public boolean contains(Command param){
		boolean result=false;
		for(Mapping mapp:mapping){
			result=mapp.getId().equals(param.getCommandName());
			if(result){
				return result;
			}
		}
		return result;
	}
	public String toString() {
		StringBuffer buffer=new StringBuffer();
		for(Mapping mapp: mapping){
			buffer.append(mapp);
		}
		for(CommandBean bean: commandBeans){
			buffer.append(bean);
		}
		return buffer.toString();
	}
	public CommandBean getCommandBeanByName(String actionName) {
		CommandBean bean=null;
		for(CommandBean cbean:commandBeans){
			if(cbean.getName().equals(actionName)){
				 bean=cbean;
				 break;
			}
		}
		return bean;
	}
	public String getCmdInfo() {
		return cmdInfo;
	}
	public void setCmdInfo(String cmdInfo) {
		this.cmdInfo = cmdInfo;
	}
}
